home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 008a / feb93cad.zip / ATTEXTED.LSP < prev    next >
Lisp/Scheme  |  1993-02-12  |  8KB  |  242 lines

  1. ;ATTEXTED.LSP
  2. ;Program by Rolando Padron 3/19/91 Revised 5/2/91
  3. ;
  4. ;This routine allows the user to create a selection set of blocks 
  5. ;containing attribute text and edit the text using an ASCII text editor.
  6. ;The program will work with all, but constant attributes.
  7. ;
  8. ;You must modify your ACAD.PGP file prior to starting up AutoCAD as follows:
  9. ;EDATXT,<EDIT.EXE> ATTEXTED.FIL,XXXXXX,,4
  10. ;where <EDIT.EXE> is the command to start your  ASCII text editor and XXXXXX
  11. ;is the amount of memory required in the shell to load and run the editor.
  12. ;
  13. (defun c:attexted ( / ss-ctr at-sslgth etemp elist etemp2 elist2 etemp3
  14.                       elist3 bk-str ctr etemp-bk bk-name bk-ctr att-prmt
  15.                       att-str at-val ss1 at-fil cmd-ex olderr)
  16.    (errset)
  17.    (f-test)
  18.    (s1)
  19.    (at-ss)
  20.    (bk-tst)
  21.    (setq ss-ctr 0)
  22.    (prompt "\nWriting file. . .")
  23.    (while (< ss-ctr at-sslgth)
  24.       (setq etemp-bk nil)
  25.       (prompt " .")
  26.       (bk-info)
  27.       (setq bk-ctr 0
  28.             etemp3 (entnext etemp)
  29.             elist3 (entget (entnext etemp))
  30.       )
  31.       (while (and (= "ATTRIB" (dxf 0 elist3)) (/= "SEQEND" (dxf 0 elist3)))
  32.          (setq bk-ctr (1+ bk-ctr)
  33.                etemp3 (entnext etemp3)
  34.                elist3 (entget etemp3)
  35.          )
  36.           (if (= bk-ctr 1) (bk-prn))
  37.           (if (= ctr nil) (setq ctr 0))
  38.           (while (< ctr bk-ctr)
  39.              (at-info)
  40.              (at-value)
  41.              (at-file)
  42.              (setq ctr (1+ ctr))
  43.           )
  44.       )
  45.       (setq ss-ctr (1+ ss-ctr)
  46.             ctr nil
  47.             etemp2 nil
  48.       )
  49.    )
  50.    (command "EDATXT")
  51.    (prompt "\nUpdating text . . .")
  52.    (at-fix)
  53.    (command "DEL" "attexted.fil")
  54.    (graphscr)
  55.    (setq ss-ctr 0)
  56.    (while (< ss-ctr at-sslgth)
  57.       (prompt " .")
  58.       (entupd (ssname ss1 ss-ctr))
  59.       (setq ss-ctr (1+ ss-ctr))
  60.    )
  61.    (s2)
  62.    (err-b4)
  63.    (princ)
  64. )
  65. ;---------------------------------AT-SS---------------------------------------
  66. (defun at-ss ()
  67.    (prompt "\n Select BLOCKS with attributes for editing:  ")
  68.    (setq ss1 (ssget)
  69.          at-sslgth (sslength ss1)
  70.          ss-ctr 0
  71.    )
  72. )
  73. ;--------------------------------BK-INFO--------------------------------------
  74. (defun bk-info ()
  75.    (setq etemp (ssname ss1 ss-ctr)
  76.          elist (entget etemp)
  77.          bk-name (dxf 2 (entget etemp))
  78.          bk-str (strcat "***Block Name:  " bk-name)
  79.    )
  80. )
  81. ;--------------------------------BK-PRN---------------------------------------
  82. (defun bk-prn ()
  83.    (setq at-fil (open "attexted.fil" "a"))
  84.    (write-line bk-str at-fil)
  85.    (close at-fil)
  86. )
  87. ;--------------------------------AT-INFO--------------------------------------
  88. (defun at-info ()
  89.    (if (= etemp-bk nil)
  90.       (setq etemp-bk (dxf -2 (tblsearch "BLOCK" bk-name))
  91.       )
  92.    )
  93.    (while (/= (dxf 0 (entget etemp-bk)) "ATTDEF")
  94.       (setq etemp-bk (entnext etemp-bk))
  95.    )      
  96.    (setq att-prmt (dxf 3 (entget etemp-bk))
  97.          att-str (strcat "***Attribute Prompt:  " att-prmt)
  98.          etemp-bk (entnext etemp-bk)
  99.    )
  100. ;-------------------------------AT-VALUE--------------------------------------
  101. (defun at-value ()
  102.    (if (= etemp2 nil)
  103.       (setq etemp2 (entnext etemp)
  104.             at-val (dxf 1 (entget etemp2))
  105.       )
  106.       (setq etemp2 (entnext etemp2)
  107.             at-val (dxf 1 (entget etemp2))
  108.       )
  109.    )
  110. )
  111. ;-------------------------------AT-FILE---------------------------------------
  112. (defun at-file ()
  113.    (setq at-fil (open "attexted.fil" "a"))
  114.    (write-line att-str at-fil)
  115.    (write-line at-val at-fil)
  116.    (close at-fil)
  117. )
  118. ;-------------------------------AT-FIX----------------------------------------
  119. (defun at-fix ( / etemp elist etemp2 elist2 str-test at-new old new at-fil)
  120.    (setq ss-ctr 0
  121.          at-fil (open "attexted.fil" "r")
  122.    )
  123.    (while (< ss-ctr at-sslgth)
  124.       (setq etemp (ssname ss1 ss-ctr)
  125.             elist (entget etemp)
  126.             etemp2 (entnext etemp)
  127.             elist2 (entget etemp2)
  128.       )
  129.       (while (and (= "ATTRIB" (dxf 0 elist2)) (/= "SEQEND" (dxf 0 elist2)))
  130.          (setq str-test (read-line at-fil))
  131.          (while str-test
  132.             (if (= (substr str-test 1 3) "***")
  133.                (setq str-test (read-line at-fil))
  134.                (setq at-new str-test
  135.                      str-test nil
  136.                )
  137.             )
  138.          )
  139.          (setq old (assoc 1 elist2)
  140.                new (cons 1 at-new)
  141.                elist2 (subst new old elist2)
  142.          )
  143.          (entmod elist2)
  144.          (setq etemp2 (entnext etemp2)
  145.                elist2 (entget etemp2)
  146.          )
  147.       )
  148.       (setq ss-ctr (1+ ss-ctr))
  149.    )
  150.    (close at-fil)
  151. )
  152. ;-----------------------------------------------------------------------------
  153. ;*****************************U T I L I T I E S*******************************
  154. ;-----------------------------------------------------------------------------
  155. (defun s1 ()
  156.    (setq cmd-ex (getvar "cmdecho"))
  157.    (setvar "cmdecho" 0)
  158. )
  159. ;-----------------------------------------------------------------------------
  160. (defun s2 ()
  161.    (setvar "cmdecho" cmd-ex)
  162.    (prompt "\nProgram Completed...")
  163. )
  164. ;-----------------------------------------------------------------------------
  165. (defun dxf (code e-list)
  166.    (cdr (assoc code e-list))
  167. )
  168. ;-----------------------------------------------------------------------------
  169. (defun f-test ()
  170.    (if (/= (findfile "attexted.fil") nil)
  171.       (progn
  172.          (prompt "\nErasing existing file...\n")
  173.          (command "DEL" "attexted.fil")
  174.       )
  175.    )
  176. )
  177. ;-----------------------------------------------------------------------------
  178. ;*************************E R R O R   H A N D L I N G*************************
  179. ;-----------------------------------------------------------------------------
  180. ;---------------------------------BK-TST--------------------------------------
  181. (defun bk-tst ( / b-el b-en blk-ok)
  182.    (setq ss-ctr 0
  183.          blk-ok 0
  184.    )
  185.    (prompt "\nChecking selection set . . .")
  186.    (while (< ss-ctr at-sslgth)
  187.       (bk-info)
  188.       (setq etemp-bk (dxf -2 (tblsearch "BLOCK" bk-name))
  189.             b-en etemp-bk
  190.       )
  191.       (while b-en
  192.          (setq b-el (entget b-en))
  193.          (if (and (= (dxf 70 b-el) 2)               
  194.                 (= (dxf 0 b-el) "ATTDEF")
  195.              )
  196.             (setq blk-ok (1+ blk-ok))
  197.          )
  198.          (setq b-en (entnext b-en))
  199.       )
  200.       (if (/= blk-ok 0) (out)        ;causes null function for error
  201.          (prompt " .")
  202.       )
  203.       (setq ss-ctr (1+ ss-ctr))  
  204.    )
  205.    (prompt " O.K.")
  206.    (princ)
  207. )
  208. ;---------------------------------AT-ERR--------------------------------------
  209. (defun at-err (m)
  210.    (cond
  211.       ((= m "null function")
  212.          (prompt "\nerror:  Blocks cannot contain CONSTANT attributes")
  213.          (setq *error* olderr)
  214.          (princ)
  215.       )
  216.       ((= m "Function cancelled")
  217.       (prompt "\n\n\nUser cancelled function")
  218.       (setq *error* olderr)
  219.       )
  220.       ((/= m nil)
  221.          (prompt "\nerror:  ")
  222.          (princ m)
  223.          (prompt "\nObjects selected possibly not blocks or don't have attributes")
  224.          (setq *error* olderr)
  225.          (princ)
  226.       )
  227.    )
  228.    (princ)
  229. )
  230. ;---------------------------------ERR-SET-------------------------------------
  231. (defun errset ()
  232.    (setq olderr *error*
  233.          *error* at-err
  234.    )
  235. )
  236. ;---------------------------------ERR-B4--------------------------------------
  237. (defun err-b4 ()
  238.    (setq *error* olderr)
  239. )
  240.  
  241.